<?php
class ManagecategoryController extends Zend_Controller_Action
{
	public function indexAction()
	{
		$model = $this->_getModel();
		$this->view->entries = $model->fetchEntries();
	}
   public function addForm()
	{
		require_once('d:/xampp/htdocs/cb/application/forms/Categories.php');
		$form1 = new Form_Category();
		$form1->setAction($this->_helper->url('save'));
        return $form1;
	}
	
public function saveAction()
    {
        $request = $this->getRequest();
        $form    = $this->addForm();
	/*	echo '<pre>';
        var_dump($form);
		exit;*/
        // check to see if this action has been POST'ed to
        if ($this->getRequest()->isPost()) {
            
            // now check to see if the form submitted exists, and
            // if the values passed in are valid for this form
            if ($form->isValid($request->getPost())) {
                
                // since we now know the form validated, we can now
                // start integrating that data sumitted via the form
                // into our model
                $model = $this->_getModel();
                $model->save($form->getValues());
                
                // now that we have saved our model, lets url redirect
                // to a new location
                // this is also considered a "redirect after post"
                // @see http://en.wikipedia.org/wiki/Post/Redirect/Get
                return $this->_helper->redirector('index');
            }
        }
        
        // assign the form to the view
        $this->view->form = $form;
    }
   public function deleteAction()
   {
   	$id = Zend_Controller_Request_Http::getQuery('cat_id');
   $request = $this->getRequest();
   $model = $this->_getModel();
   
   
   $model->delete($id);
   return $this->_helper->redirector('index');
   
   }
 protected function _getModel()
    {
        if (null === $this->_model) {
            // autoload only handles "library" compoennts.  Since this is an 
            // application model, we need to require it from its application 
            // path location.
            require_once APPLICATION_PATH . '/models/Categories.php';
            $this->_model = new Model_Categories();
        }
        return $this->_model;
    }

    /**
     * This method is essentially doing the same thing for the Form that we did 
     * above in the protected model accessor.  Same logic applies here.
     *
     * @return Form_GuestBook
     */
    protected function _getGuestbookForm()
    {
        require_once APPLICATION_PATH . '/forms/categories.php';
        $form = new Form_GuestBook();
        $form->setAction($this->_helper->url('sign'));
        return $form;
    }
}
